package com.xoa.dev.pz.controller;
import com.xoa.dev.pz.model.PzPersonWithBLOBs;
import com.xoa.dev.pz.model.PzFullReleaseWithBLOBs;
import com.xoa.dev.pz.service.PzFullReleaseService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by gsb on 2017/11/29.
 */
@Controller
@RequestMapping("/sv1/pzfullrelease")
public class PzFullReleaseController {

    @Autowired
    private PzFullReleaseService pzFullReleaseService;



    @ResponseBody
    @RequestMapping("/insertFullRelease")
    public ToJson insertFullRelease(HttpServletRequest request, PzFullReleaseWithBLOBs pzFullReleaseWithBLOBs){

        return pzFullReleaseService.insertFullRelease(request,pzFullReleaseWithBLOBs);
    }

    @ResponseBody
    @RequestMapping("/delFullRelease")
    public ToJson delFullRelease(HttpServletRequest request, int pid){
        return pzFullReleaseService.delFullRelease(request,pid);
    }


    @ResponseBody
    @RequestMapping("/upFullRelease")
    public ToJson upFullRelease(HttpServletRequest request, PzFullReleaseWithBLOBs pzFullReleaseWithBLOBs){
        return pzFullReleaseService.upFullRelease(request,pzFullReleaseWithBLOBs);

    }

    /**
     * 创建人：张丽君
     * 创建时间：17-12-07
     * 方法介绍：导出功能
     * @param request
     * @param response
     * @param page
     * @param pageSize
     * @param useFlag
     * @param pzPersonWithBLOBs
     * @param export
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectFullRelease")
    public ToJson selectFullRelease(HttpServletRequest request, HttpServletResponse response, Integer page, Integer pageSize, boolean useFlag, PzPersonWithBLOBs pzPersonWithBLOBs , String export, String pCradId, String pName){
        return pzFullReleaseService.selectFullRelease(request,response,page,pageSize,useFlag,pzPersonWithBLOBs,export,pCradId,pName);
    }

    @ResponseBody
    @RequestMapping("/selectFullReleaseId")
    public ToJson selectFullrelEaseId(HttpServletRequest request, Integer pId){
        return pzFullReleaseService.selectFullrelEaseId(request,pId);
    }

    @ResponseBody
    @RequestMapping("/selectInfoById")
    public ToJson selectInfoById(HttpServletRequest request, Integer pId){
        return pzFullReleaseService.selectInfoById(request,pId);
    }


    /**
     * 测试页面添加
     * @param request
     * @return
     */
    @RequestMapping("/goInsertPage")
    public String goInsertPage(HttpServletRequest request){
        return "app/pz/fullrelease/pzFullRelease";
    }


    /**
     * 时间注入
     * @param binder
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
            binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值，false:不能为空值
    }



    /**
     * 创建作者:  张丽军
     * 创建日期:   2017年12月7日 下午11:48
     * 方法介绍:   导入功能接口
     * @param file
     * @param response
     * @param request
     * @param session
     * @return
     */
    @RequestMapping("/importFullRelease")
    @ResponseBody
    public ToJson importFullRelease(MultipartFile file, HttpServletResponse response, HttpServletRequest request, HttpSession session){
        return pzFullReleaseService.importFullRelease(file,response,request,session);
    }
}
